package com.study.myAutoCloseAble;

/**
 * @Author tanglingyu
 * @Date: 2021/06/01/ 14:11
 * @Description
 */
public class TimeCost implements AutoCloseable {

  private long start;

  public TimeCost() {
    this.start = System.currentTimeMillis();
  }

  @Override
  public void close() {
    System.out.println("cost:" + (System.currentTimeMillis() - start));
  }

  public static void testPrint() {
    for (int i = 0; i < 5; ++i) {
      System.out.println("now" + i);
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }

  public static void main(String[] args) {
    try (TimeCost c = new TimeCost()) {
      testPrint();
    }
    System.out.println("------over-------");
  }
}





